package com.dog.basics.admin.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.mtkj.GoodTypeAddDto;
import com.dog.basics.bean.dto.admin.mtkj.GoodTypeEditDto;
import com.dog.basics.bean.vo.admin.mtkj.GoodTypeFromVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.mtkj.IMtGoodsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 商品类型表 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@Api(value = "商品类型模块", tags = "商品类型模块")
@RestController
@RequestMapping("/admin/goodtype")
@AllArgsConstructor
public class MtGoodsTypeController {

    private final IMtGoodsTypeService goodsTypeService;

    /**
     * 获取商品类型列表
     * @returns
     * @author hangdy
     * @date: 2020/11/12 14:33
     */
    @GetMapping("/findAll")
    @ApiOperation(value = "获取商品类型列表", notes = "pc:goodtype:findgoodtype")
    @PreAuthorize("@pms.hasPermission('pc:goodtype:findgoodtype')")
    public R<IPage<GoodTypeFromVo>> findGoodTypes(PageParam page){
        return R.ok(goodsTypeService.adminFindGoodType(page));
    }

    /**
     * 增加商品类型
     * @param obj
     * @return
     * @author hangdy
     */
    @SysLog("增加商品类型")
    @ApiOperation(value = "增加商品类型", notes = "pc:goodtype:goodtypeadd")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('pc:goodtype:goodtypeadd')")
    public R<Boolean> save(@Valid @RequestBody GoodTypeAddDto obj) {
        return R.ok(goodsTypeService.saveGoodType(obj));
    }


    /**
     * 修改商品类型
     * @param obj
     * @return
     * @author hangdy
     */
    @SysLog("修改商品类型")
    @ApiOperation(value = "增加商品类型", notes = "pc:goodtype:goodtypeedit")
    @PostMapping("/edit")
    @PreAuthorize("@pms.hasPermission('pc:goodtype:goodtypeedit')")
    public R<Boolean> edit(@Valid @RequestBody GoodTypeEditDto obj){

        return R.ok(goodsTypeService.editGoodType(obj));

    }

    /**
     * 删除商品类别
     * @param id
     * @return
     * @author hangdy
     */
    @SysLog("删除商品类型")
    @ApiOperation(value = "删除商品类型", notes = "pc:goodtype:goodtypedelete")
    @ApiImplicitParam(value = "商品类型Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('pc:goodtype:goodtypedelete')")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(goodsTypeService.deleteGoodType(id));
    }
}
